package edu.online.dal;

import edu.online.entity.StudentEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface StudentEntityMapper {
    @Delete({
        "delete from student",
        "where UserId = #{userid,jdbcType=CHAR}"
    })
    int deleteByPrimaryKey(String userid);

    @Insert({
        "insert into student (UserId, UserName, ",
        "Passwd, Email, Mobile, ",
        "Role, StudentName, ",
        "SSex, QQ, Requirement, ",
        "DiscountRate)",
        "values (#{userid,jdbcType=CHAR}, #{username,jdbcType=VARCHAR}, ",
        "#{passwd,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=CHAR}, ",
        "#{role,jdbcType=VARCHAR}, #{studentname,jdbcType=VARCHAR}, ",
        "#{ssex,jdbcType=CHAR}, #{qq,jdbcType=VARCHAR}, #{requirement,jdbcType=VARCHAR}, ",
        "#{discountrate,jdbcType=DECIMAL})"
    })
    int insert(StudentEntity record);

    @InsertProvider(type=StudentEntitySqlProvider.class, method="insertSelective")
    int insertSelective(StudentEntity record);

    @Select({
        "select",
        "UserId, UserName, Passwd, Email, Mobile, Role, StudentName, SSex, QQ, Requirement, ",
        "DiscountRate",
        "from student",
        "where UserId = #{userid,jdbcType=CHAR}"
    })
    @Results({
        @Result(column="UserId", property="userid", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="UserName", property="username", jdbcType=JdbcType.VARCHAR),
        @Result(column="Passwd", property="passwd", jdbcType=JdbcType.VARCHAR),
        @Result(column="Email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="Mobile", property="mobile", jdbcType=JdbcType.CHAR),
        @Result(column="Role", property="role", jdbcType=JdbcType.VARCHAR),
        @Result(column="StudentName", property="studentname", jdbcType=JdbcType.VARCHAR),
        @Result(column="SSex", property="ssex", jdbcType=JdbcType.CHAR),
        @Result(column="QQ", property="qq", jdbcType=JdbcType.VARCHAR),
        @Result(column="Requirement", property="requirement", jdbcType=JdbcType.VARCHAR),
        @Result(column="DiscountRate", property="discountrate", jdbcType=JdbcType.DECIMAL)
    })
    StudentEntity selectByPrimaryKey(String userid);

    @UpdateProvider(type=StudentEntitySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(StudentEntity record);

    @Update({
        "update student",
        "set UserName = #{username,jdbcType=VARCHAR},",
          "Passwd = #{passwd,jdbcType=VARCHAR},",
          "Email = #{email,jdbcType=VARCHAR},",
          "Mobile = #{mobile,jdbcType=CHAR},",
          "Role = #{role,jdbcType=VARCHAR},",
          "StudentName = #{studentname,jdbcType=VARCHAR},",
          "SSex = #{ssex,jdbcType=CHAR},",
          "QQ = #{qq,jdbcType=VARCHAR},",
          "Requirement = #{requirement,jdbcType=VARCHAR},",
          "DiscountRate = #{discountrate,jdbcType=DECIMAL}",
        "where UserId = #{userid,jdbcType=CHAR}"
    })
    int updateByPrimaryKey(StudentEntity record);
}